import React from "react";
import { Link, Routes, Route, useParams } from "react-router-dom";

const Home = () => <div>这是首页</div>;
const About = () => <div>这是关于页</div>;
const Detail = () => {
  // 获取动态参数的方式和之前也是一样的
  // 6版本的所有props都不携带路由信息
  const params = useParams();

  return <div>这是详情页 - {params.id}</div>;
};

const App = () => {
  return (
    <div>
      <h2>router-v6-动态参数params</h2>
      <ul>
        <li>
          <Link to="/">首页</Link>
        </li>
        <li>
          <Link to="/about">关于页</Link>
        </li>
        <li>
          <Link to="/detail/234">详情页</Link>
        </li>
      </ul>

      <hr />

      <Routes>
        {/* 动态路由的做法和之前几乎不变 */}
        <Route path="/" element={<Home></Home>}></Route>
        <Route path="/about" element={<About />}></Route>
        {/* <Route path="/detail/:id" element={<Detail />}></Route> */}

        {/* 动态可选参数 */}
        <Route path="/detail" element={<Detail />}>
          <Route path=":id" element={<Detail />}></Route>
        </Route>
      </Routes>
    </div>
  );
};

export default App;
